﻿#pragma strict
/////////////////////////////////////////////////////////////////////
//Mecanim 动画剪辑替换器.
/////////////////////////////////////////////////////////////////////
var anim:Animator;
var list:List.<AnimationClipPair1> = new List.<AnimationClipPair1>();
var isStartOverride:boolean;
var isShowLog:boolean;

function Start () {
	anim = GetComponent.<Animator>();
}

function Update () {
	if(isStartOverride){
		isStartOverride = false;
		StartOverride();
	}
}

function AddOverrideClip(originalClipName:String,clip:AnimationClip){
	if(! String.IsNullOrEmpty(originalClipName) && clip){
		list.Add(new AnimationClipPair1(originalClipName,clip));
	}
}

function StartOverride(){
	var overrideController:AnimatorOverrideController = AnimatorOverrideController();
	overrideController.runtimeAnimatorController = anim.runtimeAnimatorController;
	for(var pair:AnimationClipPair1 in list){
		Log(pair.originalClipName +":"+ pair.overrideClip);
		overrideController[pair.originalClipName] = pair.overrideClip;
	}
	anim.runtimeAnimatorController = overrideController;
	Log("override animator done.");
}

function Log(msg:String){
	if(isShowLog){
		Debug.Log(msg);
	}
}